Coverage Report

Created: 2025-11-02 11:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
D:\a\csshw\csshw\src\serde\deserialization.rs
Line
Count
Source
1
use windows::Win32::{
2
    Foundation::BOOL,
3
    System::Console::{INPUT_RECORD_0, KEY_EVENT_RECORD, KEY_EVENT_RECORD_0},
4
};
5
6
/// Deserialize a [KEY_EVENT_RECORD_0] from a u8 slice using custom binary format.
7
///
8
/// Tries to read a u16 from the given slice in little-endian format.
9
///
10
/// Panics if reconstruction fails.
11
1
pub fn deserialize_key_event_record_0(slice: &[u8]) -> KEY_EVENT_RECORD_0 {
12
1
    return KEY_EVENT_RECORD_0 {
13
1
        UnicodeChar: u16::from_le_bytes([slice[0], slice[1]]),
14
1
    };
15
1
}
16
17
/// Deserialize a [KEY_EVENT_RECORD] from a u8 slice using custom binary format.
18
/// The slice is expected to be 13 bytes long.
19
///
20
/// Layout: [1 byte KeyDown][2 bytes RepeatCount][2 bytes VirtualKeyCode]
21
///         [2 bytes VirtualScanCode][2 bytes UnicodeChar][4 bytes ControlKeyState]
22
///
23
/// Panics if reconstruction fails.
24
2
pub fn deserialize_key_event_record(slice: &[u8]) -> KEY_EVENT_RECORD {
25
2
    return KEY_EVENT_RECORD {
26
2
        // KeyDown (1 byte)
27
2
        bKeyDown: BOOL::from(slice[0] != 0),
28
2
        // RepeatCount (2 bytes LE)
29
2
        wRepeatCount: u16::from_le_bytes([slice[1], slice[2]]),
30
2
        // VirtualKeyCode (2 bytes LE)
31
2
        wVirtualKeyCode: u16::from_le_bytes([slice[3], slice[4]]),
32
2
        // VirtualScanCode (2 bytes LE)
33
2
        wVirtualScanCode: u16::from_le_bytes([slice[5], slice[6]]),
34
2
        // UnicodeChar (2 bytes LE)
35
2
        uChar: KEY_EVENT_RECORD_0 {
36
2
            UnicodeChar: u16::from_le_bytes([slice[7], slice[8]]),
37
2
        },
38
2
        // ControlKeyState (4 bytes LE)
39
2
        dwControlKeyState: u32::from_le_bytes([slice[9], slice[10], slice[11], slice[12]]),
40
2
    };
41
2
}
42
43
/// Deserialize an [INPUT_RECORD_0].`KeyEvent` from a u8 slice using custom binary format.
44
///
45
/// Panics if reconstruction fails.
46
1
pub fn deserialize_input_record_0(slice: &[u8]) -> INPUT_RECORD_0 {
47
1
    let key_event = deserialize_key_event_record(slice);
48
1
    return INPUT_RECORD_0 {
49
1
        KeyEvent: key_event,
50
1
    };
51
1
}